﻿@namespace MudBlazor
@using MudBlazor.Resources
@typeparam T
@inherits MudComponentBase
@inject InternalMudLocalizer Localizer

<div class="mud-chip-container"
     id="@_chipContainerId"
     @onkeydown="@HandleKeyDownAsync">
    <MudElement HtmlTag="@GetHtmlTag()"
                Class="@Classname"
                Style="@Style"
                @attributes="GetAttributes()"
                @onclick="@(IsButton ? this.AsNonRenderingEventHandler<MouseEventArgs>(OnClickAsync) : null)">
        @{
            if (AvatarContent is not null)
            {
                @AvatarContent
            }
            else if (!string.IsNullOrEmpty(Icon) && !ShowCheckMark)
            {
                <MudIcon Disabled="@Disabled" Icon="@Icon" Class="mud-chip-icon" Size="MudBlazor.Size.Small" Color="@GetIconColor()" />
            }
            else if (ShowCheckMark)
            {
                <MudIcon Disabled="@Disabled" Icon="@GetCheckedIcon()" Class="mud-chip-icon" Size="MudBlazor.Size.Small" />
            }
        }
        <span class="mud-chip-content">
            @if (ChildContent is null)
            {
                @if(Text is null) {
                    @($"{Value}")
                }
                else {
                    @Text
                }
            }
            else
            {
                @ChildContent
            }
            @if (IsClosable)
            {
                <MudIconButton Class="mud-chip-close-button"
                               Icon="@GetCloseIcon()"
                               OnClick="OnCloseAsync"
                               Size="MudBlazor.Size.Small"
                               Disabled="@Disabled"
                               aria-label="@Localizer[LanguageResource.MudChip_Close]"
                               tabindex="-1"/>
            }
        </span>
    </MudElement>
</div>